4.0 KB121 lines
Blame
1import type { Metadata } from "next";
2import Link from "next/link";
3import { timeAgo } from "@/lib/utils";
4import { getRepoCommits } from "@/lib/grove-api";
5
6interface Props {
7 params: Promise<{ owner: string; repo: string }>;
8 searchParams: Promise<{ ref?: string }>;
9}
10
11export async function generateMetadata({ params }: Props): Promise<Metadata> {
12 const { repo } = await params;
13 return { title: `Commits · ${repo}` };
14}
15
16
17export default async function CommitsPage({ params, searchParams }: Props) {
18 const { owner, repo } = await params;
19 const { ref: refParam } = await searchParams;
20 const ref = refParam ?? "main";
21
22 const data = await getRepoCommits(owner, repo, ref, { limit: 50 });
23
24 if (!data) {
25 return (
26 <div className="py-10">
27 <h1 className="text-lg" style={{ color: "var(--text-secondary)" }}>
28 Could not load commits
29 </h1>
30 </div>
31 );
32 }
33
34 if (data.commits.length === 0) {
35 return (
36 <div className="py-12 text-center">
37 <p className="text-sm" style={{ color: "var(--text-faint)" }}>
38 No commits yet on <span className="font-mono">{ref}</span>.
39 </p>
40 <p className="text-xs mt-1" style={{ color: "var(--text-faint)" }}>
41 Push your first commit to see history here.
42 </p>
43 </div>
44 );
45 }
46
47 return (
48 <>
49 <div style={{ border: "1px solid var(--border-subtle)" }}>
50 <table className="w-full text-sm">
51 <tbody>
52 {data.commits.map((commit: any, i: number) => {
53 const hash = commit.hash;
54 const subject = commit.subject ?? "";
55 const authorName = commit.author?.split("<")[0]?.trim() ?? commit.author;
56 const initial = authorName?.[0]?.toUpperCase() ?? "?";
57 return (
58 <tr
59 key={commit.hash}
60 className="hover-row"
61 style={{
62 borderTop:
63 i > 0 ? "1px solid var(--divide)" : undefined,
64 }}
65 >
66 <td className="py-2 pl-3 pr-2 w-8">
67 <span
68 title={commit.author}
69 style={{
70 display: "inline-flex",
71 alignItems: "center",
72 justifyContent: "center",
73 width: 22,
74 height: 22,
75 borderRadius: "50%",
76 backgroundColor: "var(--bg-inset)",
77 border: "1px solid var(--border-subtle)",
78 color: "var(--text-muted)",
79 fontSize: "0.65rem",
80 cursor: "default",
81 }}
82 >
83 {initial}
84 </span>
85 </td>
86 <td className="py-2 pr-3 truncate" style={{ maxWidth: 0 }}>
87 <Link
88 href={`/${owner}/${repo}/commit/${hash}`}
89 className="hover:underline"
90 style={{ color: "var(--text-primary)" }}
91 >
92 {subject}
93 </Link>
94 </td>
95 <td
96 className="py-2 pr-3 font-mono text-xs w-16 hidden sm:table-cell"
97 >
98 <Link
99 href={`/${owner}/${repo}/commit/${hash}`}
100 style={{ color: "var(--accent)" }}
101 className="hover:underline"
102 >
103 {hash.slice(0, 7)}
104 </Link>
105 </td>
106 <td
107 className="py-2 pr-3 text-xs w-20 text-right"
108 style={{ color: "var(--text-faint)" }}
109 >
110 {timeAgo(commit.timestamp)}
111 </td>
112 </tr>
113 );
114 })}
115 </tbody>
116 </table>
117 </div>
118 </>
119 );
120}
121